package com.attilax.formH5;

import com.attilax.io.filex;
import com.attilax.io.pathx;

public class EncodeX {
	
	public static void main(String[] args) {
//		String s="window.document.getElementById('editor').value='\"aaa\"'";
//		s=filex.read("c:\\1.txt");
//		System.out.println(jsEncode( s));
		
//		 String js=filex.read(pathx.classPath(EditorForm.class)+"/editor__form.js");
//		 String p2_txt="\\'aaa\\'";
//	//	String script = js.replace("@txt", p2_txt);
//		 p2_txt = p2_txt.replace("\\", "\\\\");
//		System.out.println(p2_txt);
	}
/**
 * replace double quoue,should use  jsEncodeSingleQuoue as often useage
 * @param p2_txt
 * @return
 */
	public static String jsEncode(String p2_txt) {
		// TODO Auto-generated method stub
		p2_txt = p2_txt.replace("\\", "\\\\");
		String doubleQuoto="\"";
		String replaceAll = p2_txt.replace(doubleQuoto, "\\\"");	
		  replaceAll = replaceAll.replace("\r", "\\r"); 
		  replaceAll = replaceAll.replace("\n", "\\n");
		
		return replaceAll;
	}
	
	public static String jsEncode_ReplaceSingleQuoue(String p2_txt) {
		return p2_txt;}
	
	
	/**
	 * jeig should common  if html hto yva double queuo ll...
	 * @param p2_txt
	 * @return
	 */
	public static String jsEncodeSingleQuoue(String p2_txt) {
		// TODO Auto-generated method stub
		
		p2_txt = p2_txt.replace("\\", "\\\\");
		String SingleQuoue="\'";
		String replaceAll = p2_txt.replace(SingleQuoue, "\\\'");		  
		
		  replaceAll = replaceAll.replace("\r", "\\r"); 
		  replaceAll = replaceAll.replace("\n", "\\n");
		  
		return replaceAll;
	}


}
